# -*- coding: utf-8 -*-
import requests
service_url = "http://192.168.10.228:3009/api/bot/send_to_user"

payload = "message test"
class ChatRobotClient:
  id = 0
  name = "小王同学"
  header = {
      'x-api-key': '744e60e07997658f259120934f34ffc005fa3a7a8869f4e10e61d8f6d384e5397b22756964223a322c226e6f6e6365223a222f372b7a4a4e4844504755414141414144327958597a62394f356b516c6d3772227d',
      'Content-Type': 'text/plain'
  }
  def __init__(self, id, name, header):
      self.id = id
      self.name = name
      if header == None:
         self.header = header

  def send_message(self, id, message):
      url = service_url + "/" + id
      response = requests.request("POST", url, headers=self.header, data=message)
      response.encoding = response.apparent_encoding
      # 查看响应内容，response.text 返回的是Unicode格式的数据
      print(response.text)
      # 查看响应头部字符编码
      print(response.encoding)
      # 查看响应码
      print(response.status_code)
      return response.status_code

if __name__ == '__main__':
    client = ChatRobotClient(2, "小王同学") 
    client.send_message(service_url, 1, payload)